package com.own.component.security.condition;

import com.own.constant.ConstantCommon;
import com.own.constant.ConstantValue;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * MenuAspectCondition
 *
 * @author chenxueli
 * @date 2022-08-10 11:07:00
 */
public class MenuAspectCondition implements Condition {

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // 获取两个参数信息
        var flag1 = context.getEnvironment().getProperty(ConstantValue.CONFIG_VALUE_CONTENT + "security.permission.enable");
        if (ConstantCommon.FALSE.equals(flag1)) {
            return false;
        }
        var flag2 = context.getEnvironment().getProperty(ConstantValue.CONFIG_VALUE_CONTENT + "security.permission.enable-menu");
        return !ConstantCommon.FALSE.equals(flag2);
    }

}
